﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Simple.Repository.Migrations
{
    public partial class _39 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "ChildAttendanceRule",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "主键", collation: "ascii_general_ci"),
                    EntryTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "入园时间"),
                    OutSchoolTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "出园时间"),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "软删标记"),
                    CreatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "创建时间"),
                    CreatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "创建用户Id", collation: "ascii_general_ci"),
                    UpdatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "更新时间"),
                    UpdatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "更新用户Id", collation: "ascii_general_ci"),
                    OrganizationId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "机构Id", collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ChildAttendanceRule", x => x.Id);
                },
                comment: "幼儿考勤规则")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "ChildAttendance",
                columns: table => new
                {
                    ChildId = table.Column<Guid>(type: "char(36)", nullable: false, comment: "幼儿id", collation: "ascii_general_ci"),
                    ChildAttendanceRuleId = table.Column<Guid>(type: "char(36)", nullable: false, comment: "幼儿规则id", collation: "ascii_general_ci"),
                    ChildrenId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    AttendanceRecordIds = table.Column<string>(type: "longtext", nullable: true, comment: "考勤原始记录id集合（\",\"隔开）")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Today = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "今天日期"),
                    AttendanceEntryTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "考勤入园时间"),
                    OutSchoolTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "考勤出园时间"),
                    IsLate = table.Column<bool>(type: "tinyint(1)", nullable: true, comment: "是否迟到"),
                    IsEarly = table.Column<bool>(type: "tinyint(1)", nullable: true, comment: "是否早退"),
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "主键", collation: "ascii_general_ci"),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "软删标记"),
                    CreatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "创建时间"),
                    CreatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "创建用户Id", collation: "ascii_general_ci"),
                    UpdatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "更新时间"),
                    UpdatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "更新用户Id", collation: "ascii_general_ci"),
                    OrganizationId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "机构Id", collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ChildAttendance", x => new { x.ChildId, x.ChildAttendanceRuleId });
                    table.ForeignKey(
                        name: "FK_ChildAttendance_ChildAttendanceRule_ChildAttendanceRuleId",
                        column: x => x.ChildAttendanceRuleId,
                        principalTable: "ChildAttendanceRule",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ChildAttendance_Childrens_ChildrenId",
                        column: x => x.ChildrenId,
                        principalTable: "Childrens",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_ChildAttendance_ChildAttendanceRuleId",
                table: "ChildAttendance",
                column: "ChildAttendanceRuleId");

            migrationBuilder.CreateIndex(
                name: "IX_ChildAttendance_ChildId_ChildAttendanceRuleId",
                table: "ChildAttendance",
                columns: new[] { "ChildId", "ChildAttendanceRuleId" });

            migrationBuilder.CreateIndex(
                name: "IX_ChildAttendance_ChildrenId",
                table: "ChildAttendance",
                column: "ChildrenId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ChildAttendance");

            migrationBuilder.DropTable(
                name: "ChildAttendanceRule");
        }
    }
}
